home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tech Arsenal 1
/
Tech Arsenal (Arsenal Computer).ISO
/
tek-02
/
tsptp.zip
/
FIBONACC.PAS
< prev
next >
Wrap
Pascal/Delphi Source File
|
1993-04-09
|
3KB
|
82 lines
(******************************************************************************)
(* FIBONACC.PAS *)
(* *)
(* The classic recursive benchmark, implemented with local procedures. *)
(******************************************************************************)
PROGRAM FIBONACCI(Output);
(******************************************************************************)
(* TIMING *)
(******************************************************************************)
(*$IFNDEF TopSpeed *)
(*%F TRUE *** Compile for Turbo Pascal ***)
USES TPBench;
(*%E*)
(*$ELSE *** Compile for TopSpeed Pascal ***)
IMPORT TSBench *;
(*$ENDIF *)
(******************************************************************************)
VAR
FibVal : BmInt;
PROCEDURE Fibo;
(* Compute the first 25 numbers in the sequence. *)
FUNCTION Fib(n : BmInt): BmInt;
(* This local procedure returns the value of the nth fibonacci number *)
BEGIN
IF n = 1 THEN
Fib := 0
ELSE IF n = 2 THEN
Fib := 1
ELSE
Fib := Fib(n - 1) + Fib(n - 2);
END;
VAR
i : BmInt;
BEGIN
(*** The 25th number in the sequence is the largest representable with ***)
(*** 16 bits. ***)
FOR i := 1 TO 25 DO
FibVal := Fib(i);
END;
BEGIN
WriteLn('Fibonacci Benchmark');
(******************************************************************************)
(* Compute the looping overhead. The Dummy procedure must have some side- *)
(* effect so that it is not optimised out of existence. *)
(******************************************************************************)
StartTimer; (* Start the clock. *)
REPEAT
Dummy;
UNTIL NullTimesUp;
(******************************************************************************)
(* Now run the benchmark. Note that the Dummy procedure is also called so *)
(* that we can eliminate its overhead from the looping overhead. *)
(******************************************************************************)
StartTimer; (* Start the clock. *)
REPEAT
Fibo;
Dummy
UNTIL BenchTimesUp;
(******************************************************************************)
ReportTimes;
WriteLn;
WriteLn('Fib(25) = ', FibVal:3);
END.